<template>
  <div>
    <el-button plain type="primary" @click="roleEdit()"  style="margin-left: 20px;margin-top: 20px">添加权限</el-button>
    <el-table
      :data="roleInfoList"
      border
      stripe
      v-loading="dataListLoading"
      style="width: 100%; margin-top: 20px;">
      <el-table-column prop="roleName" header-align="center" align="center" label="权限名称"></el-table-column>
      <el-table-column prop="subjectCode" header-align="center" align="center" label="课题编码"></el-table-column>
      <el-table-column prop="researchName" header-align="center" align="center" label="课题名称"></el-table-column>
      <el-table-column prop="siteCode" header-align="center" align="center" label="中心编码"></el-table-column>
      <el-table-column prop="siteName" header-align="center" align="center" label="中心名称"></el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="250" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="deleteRole(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <role-update v-if="updateVisible" ref="addOrUpdate" @refreshDataList="getdata"></role-update>
  </div>
</template>

<script>
// import role from '@/api/role'
import user from '../../api/user'
import myUtils from '../../api/myUtils'
import roleUpdate from './role-update.vue'
import site from '../../api/site'
export default {
  components: {
    roleUpdate
  },
  data() {
    return {
      dataList: [
        {
          id:0,
        },
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      roleInfoList:[],
      updateVisible:false
    }
  },
  created() {
    this.getdata();
  },
  methods: {
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    getdata()
    {
      // console.log("++++++++++++++++++++++++++")
      // console.log(this.$route.query.userNum)

      user.getUserVoByUserNum(this.$route.query.userNum).then(
        response=>
        {
          let data = response.data
          this.roleInfoList =data.roleInfoList
          console.log(this.roleInfoList)
        }
      );
    },
    deleteRole(id)
    {
      let role =myUtils.getRole(this.$route.query.subjectPkId,this.$store.getters.roles,this.$store.getters.isSystemAdministrator);
      if(role !== 8) //总管理员才能操作
      {
        this.$message.error("您不是系统管理员");
        return;
      }
      this.$confirm(
        `确定对改权限进行删除操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(()=>{
        user.deleteRole(id).then(( response ) => {
          console.log(response)
          if (response.code  === '000000') {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 700,
              onClose: () => {
                this.getdata()
              }
            });
          } else {
            this.$message.error(response.msg);
          }
        });
      })
    },
    roleEdit()
    {
      let userNum = this.$route.query.userNum
      let dataList = this.roleInfoList
      console.log("111" + userNum)
      console.log(dataList)
      let role =myUtils.getRole(this.$route.query.subjectPkId,this.$store.getters.roles,this.$store.getters.isSystemAdministrator);
      if(role !== 8) //总管理员才能操作
      {
        return;
      }
      user.getUserVoByUserNum(userNum).then(( response ) => {
        console.log("aaaaaa")
        console.log(response)
      })
      this.updateVisible = true;
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(userNum, dataList);
      });
      console.log(this.updateVisible)
    },
  },
}
</script>
<style>

</style>
